package com.itheima.controller;

import com.itheima.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/test01")
    public ModelAndView test01(ModelAndView modelAndView, Integer id, String username) {

        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", "id:" + id + ",username:" + username);

        modelAndView.setViewName("message");
        return modelAndView;
    }

    @RequestMapping("/test02")
    public ModelAndView test02(ModelAndView modelAndView, Integer id, String username) {

        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", "id:" + id + ",username:" + username);

        modelAndView.setViewName("message");
        return modelAndView;
    }

    @RequestMapping("/test03")
    public ModelAndView test03(Integer id, String username) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", "id:" + id + ",username:" + username);

        modelAndView.setViewName("message");
        return modelAndView;
    }

    @RequestMapping("/test04")
    public ModelAndView test04(Integer id, String username) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", "id:" + id + ",username:" + username);

        modelAndView.setViewName("message");
        return modelAndView;
    }

    @RequestMapping("/test05")
    public ModelAndView test05(User user) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", user.toString());

        modelAndView.setViewName("message");
        return modelAndView;
    }

    @RequestMapping("/test06")
    public ModelAndView test06(User user) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", user.toString());

        modelAndView.setViewName("message");
        return modelAndView;
    }

    @RequestMapping("/test07") //User包含Account
    public ModelAndView test07(User user) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", user.toString());

        modelAndView.setViewName("message");
        return modelAndView;
    }

    @RequestMapping("/test08") //User包含Account
    public ModelAndView test08(User user) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", user.toString());

        modelAndView.setViewName("message");
        return modelAndView;
    }

    @RequestMapping("/test09")
    public ModelAndView test09(String[] args) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", Arrays.toString(args));

        modelAndView.setViewName("message");
        return modelAndView;
    }

    @RequestMapping("/test10")
    public ModelAndView test10(String[] args) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", Arrays.toString(args));

        modelAndView.setViewName("message");
        return modelAndView;
    }

    @RequestMapping("/test11")
    //List集合必须使用@RequestParam注解绑定参数
    public ModelAndView test11(@RequestParam("args")List<String> args) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", args);

        modelAndView.setViewName("message");
        return modelAndView;
    }

    @RequestMapping("/test12")
    //List集合必须使用@RequestParam注解绑定参数
    public ModelAndView test12(@RequestParam("args")List<String> args) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", args);

        modelAndView.setViewName("message");
        return modelAndView;
    }

}
